<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>誉禾植物店</title>
  <!-- bootstrap样式 -->
  <link href="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
  <!-- element-ui的样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

  <!-- vue2框架的js和emenet-ui的js -->
  <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <!-- 可以发送jquery请求 -->
  <script src="../js/jquery.min.js"></script>
  <!-- bootstrap框架 -->
  <script src="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
  <!-- js动画 -->
  <script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
  <!-- 用于发送请求 -->
  <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<!-- 管理员登录 -->
<style>
  * {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }
  #login {
    /* background: url('../images/login_bg.jpg') no-repeat;
    background-size: 100% 100%; */
    height: 100vh;
    width: 100%;
    overflow: hidden;
  }
  .login_div {
    background: url('../images/login.png') no-repeat;
    background-size: 100% 100%;
    width: 50%;
    height: 70%;
    margin: auto;
    margin-top: 10%;
    padding-top: 4%;
  }
  h2 {
    text-align: center;
    font-weight: 600;
  }
  input {
    outline: none;
    border: 0;
    height: 50px;
    width: 300px;
    background-color: #fef5d4;
    padding-left: 3%;
    border-radius: 10px;
  }
  table {
    border-collapse: separate;
    border-spacing: 20px;
  }
  button {
    border: 0;
    height: 50px;
    width: 120px;
    border-radius: 5px;
    background-color: #97df4f;
    font-size: 18px;
    font-weight: 600;
  }
  a {
    text-decoration: none;
    color: #579e11;
  }
</style>
<body>
  <div id="login">
    <div class="login_div">
      <h2 style="color: #579e11;">管理员登录</h2>
      <div style="display: flex;margin-top: 3%;">
        <table style="margin: auto;">
          <tr>
            <td>账号：</td>
            <td><input type="text" v-model="ruleFrom.account" placeholder="请输入您的账号"></td>
          </tr>
          <tr>
            <td>密码：</td>
            <td><input type="password" v-model="ruleFrom.password" placeholder="请输入您的密码"></td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: center;">
              <button @click="login()">登录</button>
            </td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: center;">
              <p>还没有账号？立即<a href="./register.html">注册</a></p>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</body>
<script>
  new Vue({
    el: '#login',
    data() {
      return {
        ruleFrom: {}
      }
    },
    created(){
      // 进入登录页面的时候进行一下清除数据
      localStorage.removeItem("managentId");
    },
    methods: {
      // 登录
      async login(){
        if (this.ruleFrom.password == "") {
          this.$message.error("请输入密码");
          return;
        }
        const {data : result} = await this.$http.post("http://localhost:9081/plants_managent/login",this.ruleFrom);
        console.log(result);
        if (result.flag) {
          // 存入管理员id
          localStorage.setItem("managentId",result.message);
          // 跳转首页
          window.location.href = './home.html';
        }else {
          this.$message.error(result.message);
        }
      }
    }
  })
</script>

</html>